package eval;

//Amit:
import java.util.ArrayList;
import java.util.List;

import com.google.inject.Guice;

import eval.exceptions.ConfigurationException;
import eval.experiment.Experiment;
import com.google.inject.Injector;

import eval.gui.ResultsFrame;
import eval.guice.InjectorModule;
import eval.results.*;
import eval.utilities.configuration.ExperimentConfiguration;

public class Main {

	/**
	 * @param args
	 */
	
	
	public static void main(String[] args) {
		List<IResultsData> resultsData = new ArrayList<IResultsData>();
		String resFileName = ExperimentSerializer.generateFileName();
		for(int i=0;i<args.length;i++) {
			loadConfiguration(args[i]);
			Injector injector = Guice.createInjector(new InjectorModule());
			Experiment experiment = new Experiment(injector);
			experiment.runExperiment(resFileName);
			IResultsData toPrint = experiment.getResultsData();
			ResultsToCsv print = new ResultsToCsv(toPrint,ExperimentSerializer.generateFileNameToCsv(resFileName,toPrint));
			print.write();
			resultsData.add(toPrint);
		}
		ResultsFrame gui = new ResultsFrame(resultsData,resFileName);
		gui.display();
	}
	
	/**
	 * Load configuration file system
	 * */
	public static void loadConfiguration(String configurationFilepath) {
		ExperimentConfiguration provisionerConfiguration = ExperimentConfiguration
				.getSingleton();
		try {
			provisionerConfiguration.loadFromFile(configurationFilepath);
		} catch (ConfigurationException e) {
			e.printStackTrace();
			throw new RuntimeException("Error loading " + configurationFilepath
					+ ": " + e.getMessage());
		}

	}

}
